package com.example.yyy

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_toolbar.*
import org.jetbrains.anko.toast

class ToolbarActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_toolbar)
        toolBar()
    }
    fun toolBar(){
        tl_tb_head.title = "这是工具栏的主标题"
        tl_tb_head.setTitleTextColor(Color.RED)
        tl_tb_head.setLogo(R.drawable.tl)
        tl_tb_head.subtitle = "这是副标题"
        tl_tb_head.setSubtitleTextColor(Color.YELLOW)
        tl_tb_head.setBackgroundColor(Color.GREEN)
        setSupportActionBar(tl_tb_head)
        tl_tb_head.setNavigationIcon(R.drawable.tl)
        tl_tb_head.setNavigationOnClickListener {
            toast("点击事件")
        }
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.menu_option,menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when(item.itemId){
            R.id.menu1 -> toast("menu1")
            R.id.menu2 -> toast("menu2") 
            R.id.menu3 -> toast("menu3")
        }
        return true
    }
}